package panels;

import islemler.DegisiklikTalebiYonet;
import islemler.KullaniciYonet;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import dosyaokuyaz.DosyaIslem;

import nesne.DegisiklikTalebi;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DegisiklikTalebiListelePanel extends javax.swing.JPanel {
	private JTable degisiklikTalebiTablosu;
	private JButton guncelleButonu;
	DegisiklikTalebi degisiklikTalebi[];
	private JButton sureButon;
	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new DegisiklikTalebiListelePanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public DegisiklikTalebiListelePanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
			{
				DegisiklikTalebiYonet dtYonet = new DegisiklikTalebiYonet();
				degisiklikTalebi = dtYonet.degTalebiAlmaIslemi();
				if (degisiklikTalebi != null) {
				String[][] tablo = new String[degisiklikTalebi.length][2];
				for (int i=0; i<degisiklikTalebi.length; i++) {
					tablo[i][0] = Integer.toString(degisiklikTalebi[i].getTalepNo());
					tablo[i][1] = degisiklikTalebi[i].getIsmi();
				}
				TableModel degisiklikTalebiTablosuModel = 
					new DefaultTableModel(
							tablo,
							new String[] { "Talep No", "Talep Eden" });
				degisiklikTalebiTablosu = new JTable();
				degisiklikTalebiTablosu.setModel(degisiklikTalebiTablosuModel);
				}
				{
					guncelleButonu = new JButton();
					guncelleButonu.setText("guncelle");
					guncelleButonu.addActionListener(new GuncellemeIslemi());
				}
				{
					sureButon = new JButton();
					sureButon.setText("Sure");
					sureButon.addActionListener(new SureIslemi());
				}
					thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
						.addContainerGap()
						.addComponent(degisiklikTalebiTablosu, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
						.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						    .addComponent(guncelleButonu, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
						    .addComponent(sureButon, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
						.addContainerGap(139, 139));
					thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
						.addContainerGap(96, 96)
						.addGroup(thisLayout.createParallelGroup()
						    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
						        .addComponent(degisiklikTalebiTablosu, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 21, Short.MAX_VALUE))
						    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
						        .addGap(44)
						        .addComponent(guncelleButonu, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
						        .addGap(19)
						        .addComponent(sureButon, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 0, Short.MAX_VALUE)))
						.addContainerGap(133, 133));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	public void guncellePanel() {
		this.removeAll();
		DegTalebiGuncellemePaneli degTalGunPanel = new DegTalebiGuncellemePaneli(degisiklikTalebi[degisiklikTalebiTablosu.getSelectedRow()]);
		degTalGunPanel.setSize(600, 300);
		add(degTalGunPanel);
		this.revalidate();
		this.repaint();
		degTalGunPanel.revalidate();
		degTalGunPanel.repaint();
	}
	
	public class GuncellemeIslemi implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			guncellePanel();
		    }
		}
	
	public class SureIslemi implements ActionListener{
		
	
	@Override
	public void actionPerformed(ActionEvent e) {
		DegisiklikTalebiYonet degTalYonet = new DegisiklikTalebiYonet();
		degTalYonet.zamanSaklama();
		
	}
  }
}